const connection = require('../app/database.js')
// 所有和数据库相关的操作
class fileServer {
    // avatar表填入数据
    async create(filename , mimetype , size  ,id){
        const statement = 'INSERT INTO avatar (filename , mimetype , size, user_id) VALUES (?, ? , ? ,?);'
        const [result] = await connection.execute(statement ,[filename , mimetype , size  ,id])
        return result
    }

    async showAvatarByUserId(userId){
        const statement = 'SELECT * FROM avatar WHERE user_id = ?;'
        const [result] = await connection.execute(statement , [userId])
        return result[result.length - 1] // 返回最新上传的头像
    }

}
module.exports = new fileServer()